//
//  UIButton+Extension.swift
//  My_Weibo
//
//  Created by 正能量 on 16/8/23.
//  Copyright © 2016年 正能量. All rights reserved.
//

import UIKit

extension UIButton {
    convenience init(title:String?,
                     fontSize:CGFloat = 17,
                     color:UIColor = UIColor.darkGrayColor(),
                     imageName: String? = nil,
                     backgroundImage: String? = nil) {
        
        self.init()
        
        self.setTitle(title, forState: .Normal)
        self.setTitleColor(color, forState: .Normal)
        if let backImage = backgroundImage {
            self.setBackgroundImage(UIImage(named: backImage),forState: .Normal)
            self.setBackgroundImage(UIImage(named: backImage + "_highlighted"), forState: .Highlighted)
        }
        if let imgName = imageName {
            self.setImage(UIImage(named: imgName), forState: .Normal)
            self.setImage(UIImage(named: imgName + "_highlighted"), forState: .Highlighted)
        }
        sizeToFit()
    }
}
